package dhm.com.dhmshop.framework.module.home.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import dhm.com.dhmshop.R;
import dhm.com.dhmshop.adapter.mine.ShopAdapter;
import dhm.com.dhmshop.base.BaseActiity;
import dhm.com.dhmshop.base.Presenter.PressenterImpl;
import dhm.com.dhmshop.base.netWork.Constant;
import dhm.com.dhmshop.base.netWork.LoginContract;
import dhm.com.dhmshop.entity.Bean;
import dhm.com.dhmshop.entity.GetMyShopinfo;
import dhm.com.dhmshop.entity.GetMysearch;
import dhm.com.dhmshop.framework.module.commodity.activity.CommodityDetailsActivity;
import dhm.com.dhmshop.utils.SpUtils;

public class SearchActivity extends BaseActiity implements LoginContract.IView {

    @BindView(R.id.et_seach)
    EditText etSeach;
    @BindView(R.id.searchclear)
    ImageView searchclear;
    @BindView(R.id.recycle_search)
    TagFlowLayout recycle_search;
    @BindView(R.id.his_search)
    TagFlowLayout his_search;
    @BindView(R.id.sou)
    RelativeLayout sou;
    @BindView(R.id.recycle_star)
    XRecyclerView recycleStar;
    @BindView(R.id.xiao)
    TextView xiao;
    @BindView(R.id.price)
    CheckBox price;
    @BindView(R.id.priceup)
    ImageView priceup;
    @BindView(R.id.pricedown)
    ImageView pricedown;
    @BindView(R.id.renqi)
    TextView renqi;
    @BindView(R.id.recy_line)
    LinearLayout recy_line;
    @BindView(R.id.search_bar)
    LinearLayout searchBar;
    @BindView(R.id.image)
    LinearLayout image;
    @BindView(R.id.shop_xiao)
    TextView shopXiao;
    @BindView(R.id.shop_price)
    CheckBox shopPrice;
    @BindView(R.id.shop_priceup)
    ImageView shopPriceup;
    @BindView(R.id.shop_pricedown)
    ImageView shopPricedown;
    @BindView(R.id.shop_lin_price)
    LinearLayout shopLinPrice;
    @BindView(R.id.shop_renqi)
    TextView shopRenqi;
    @BindView(R.id.time)
    CheckBox time;
    @BindView(R.id.timeup)
    ImageView timeup;
    @BindView(R.id.timedown)
    ImageView timedown;
    @BindView(R.id.lin_time)
    LinearLayout linTime;
    @BindView(R.id.shop_search)
    LinearLayout shopSearch;
    private PressenterImpl pressenter;

    private int offset;

    private String uid;
    private boolean ishis = false;
    private ShopAdapter shopAdapter;
    private List<GetMyShopinfo.DataBean> allSearch;
    private String value;
    private String isshow;
    private String shop_id;
    private String ct1;
    private String ct2;
    private String type;

    @Override
    protected int getLayout() {
        return R.layout.activity_search;
    }

    @SuppressLint("NewApi")
    @Override
    protected void initView() {
        getWindow().setStatusBarColor(getResources().getColor(R.color.main));
        //状态栏中的文字颜色和图标颜色，需要android系统6.0以上，而且目前只有一种可以修改（一种是深色，一种是浅色即白色）
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            //修改为深色，因为我们把状态栏的背景色修改为主题色白色，默认的文字及图标颜色为白色，导致看不到了。
//            getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

            Window window = getWindow();
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);


        }
        ButterKnife.bind(this);
        pressenter = new PressenterImpl();
        pressenter.attachView(this);
        uid = SpUtils.getString(this, "uid");
        GridLayoutManager manager = new GridLayoutManager(this, 2);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recycleStar.setLayoutManager(manager);
//        1.店铺页面过来的 2.分类页面过来的   3.搜索按钮过来的
        type = getIntent().getStringExtra("type");
        offset = 1;
        isshow = "1";
        recycleStar.setLoadingMoreEnabled(true);
        recycleStar.setPullRefreshEnabled(true);
        if (type.equals("1")) {
            searchBar.setVisibility(View.GONE);
            shopSearch.setVisibility(View.VISIBLE);
            sou.setVisibility(View.GONE);
            shop_id = getIntent().getStringExtra("shop_id");
            ct1 = getIntent().getStringExtra("ct1");
            ct2 = getIntent().getStringExtra("ct2");
            Map<String, String> map = new HashMap<>();
            map.put("token", Constant.TOKEN);
            map.put("shop_id", shop_id);
            if (ct1!=null&&!ct1.equals("")){
                map.put("ct1", ct1);
            }
            if (ct2!=null&&!ct2.equals("")){
                map.put("ct2", ct2);
            }
            map.put("page",offset+"");
            pressenter.sendMessage(this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);
            recycleStar.setLoadingListener(new XRecyclerView.LoadingListener() {
                @Override
                public void onRefresh() {
                    offset = 1;
                    Map<String, String> map = new HashMap<>();
                    map.put("token", Constant.TOKEN);
                    map.put("shop_id", shop_id);
                    if (ct1!=null&&!ct1.equals("")){
                        map.put("ct1", ct1);
                    }
                    if (ct2!=null&&!ct2.equals("")){
                        map.put("ct2", ct2);
                    }
                    map.put("page",offset+"");
                    pressenter.sendMessage(SearchActivity.this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);
                }
                @Override
                public void onLoadMore() {
                    Map<String, String> map = new HashMap<>();
                    map.put("token", Constant.TOKEN);
                    map.put("shop_id", shop_id);
                    if (ct1!=null&&!ct1.equals("")){
                        map.put("ct1", ct1);
                    }
                    if (ct2!=null&&!ct2.equals("")){
                        map.put("ct2", ct2);
                    }
                    map.put("page",offset+"");
                    pressenter.sendMessage(SearchActivity.this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);
                }
            });
        } else if (type.equals("2")) {
            searchBar.setVisibility(View.VISIBLE);
            shopSearch.setVisibility(View.GONE);
            sou.setVisibility(View.GONE);
            String cate_id = getIntent().getStringExtra("cate_id");
            String goods_name=getIntent().getStringExtra("goods_name");
            etSeach.setText(goods_name);

            Map<String,String> map=new HashMap<>();
            map.put("token",Constant.TOKEN);
            map.put("cate_id",cate_id);
            map.put("page",offset+"");
            pressenter.sendMessage(this,Constant.CateSearch,map,GetMyShopinfo.class);

            recycleStar.setLoadingListener(new XRecyclerView.LoadingListener() {
                @Override
                public void onRefresh() {
                    offset = 1;
                    Map<String,String> map=new HashMap<>();
                    map.put("token",Constant.TOKEN);
                    map.put("cate_id",cate_id);
                    map.put("page",offset+"");
                    pressenter.sendMessage(SearchActivity.this,Constant.CateSearch,map,GetMyShopinfo.class);
                }
                @Override
                public void onLoadMore() {
                    Map<String,String> map=new HashMap<>();
                    map.put("token",Constant.TOKEN);
                    map.put("cate_id",cate_id);
                    map.put("page",offset+"");
                    pressenter.sendMessage(SearchActivity.this,Constant.CateSearch,map,GetMyShopinfo.class);
                }
            });
        } else {
            searchBar.setVisibility(View.GONE);
            shopSearch.setVisibility(View.GONE);
            sou.setVisibility(View.VISIBLE);
            recycleStar.setLoadingListener(new XRecyclerView.LoadingListener() {
                @Override
                public void onRefresh() {
                    offset = 1;
                    search(value);
                }

                @Override
                public void onLoadMore() {
                    search(value);
                }
            });
        }

    }

    @Override
    protected void initData() {
        etSeach.addTextChangedListener(new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                String s = etSeach.getText().toString();
                if (s.length() <= 0) {
                    sou.setVisibility(View.VISIBLE);
                } else {
                    sou.setVisibility(View.GONE);
                }
            }
        });


        Map<String, String> map = new HashMap<>();
        map.put("token", Constant.TOKEN);
        pressenter.sendMessage(SearchActivity.this, Constant.HotSearch, map, GetMysearch.class);
    }

    private void search(String value) {
        this.value = value;
        Map<String, String> map = new HashMap<>();
        map.put("token", Constant.TOKEN);
        map.put("goods_name", value);
        map.put("page", offset + "");
        map.put("uid", uid);
        pressenter.sendMessage(SearchActivity.this, Constant.GoodSearch, map, GetMyShopinfo.class);
    }


    @Override
    public void requesta(Object data) {
        if (data instanceof GetMysearch) {
            GetMysearch getMysearch = (GetMysearch) data;

            if (ishis) {
//设置引入流式布局
                recycle_search.setAdapter(new TagAdapter<String>(getMysearch.getData()) {
                    @Override
                    public View getView(FlowLayout parent, int position, String s) {
                        //加入你的布局
                        TextView tv = (TextView) View.inflate(SearchActivity.this, R.layout.text_flow, null);
                        tv.setText(s);
                        return tv;
                    }
                });
                //点击流式布局跳转到下个界面
                recycle_search.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
                    @Override
                    public boolean onTagClick(View view, int position, FlowLayout parent) {
                        etSeach.setText(getMysearch.getData().get(position));
                        search(getMysearch.getData().get(position));
                        return true;
                    }
                });
            } else {
                ishis = true;
                //设置引入流式布局
                his_search.setAdapter(new TagAdapter<String>(getMysearch.getData()) {
                    @Override
                    public View getView(FlowLayout parent, int position, String s) {
                        //加入你的布局
                        TextView tv = (TextView) View.inflate(SearchActivity.this, R.layout.text_flow, null);
                        tv.setText(s);
                        return tv;
                    }
                });
                //点击流式布局跳转到下个界面
                his_search.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
                    @Override
                    public boolean onTagClick(View view, int position, FlowLayout parent) {
                        etSeach.setText(getMysearch.getData().get(position));
                        search(getMysearch.getData().get(position));
                        return true;
                    }
                });

                Map<String, String> map = new HashMap<>();
                map.put("token", Constant.TOKEN);
                map.put("uid", uid);
                pressenter.sendMessage(this, Constant.GetMysearch, map, GetMysearch.class);
            }
        } else if (data instanceof Bean) {
            Bean bean = (Bean) data;
            if (bean.getCode() == 1) {
                initData();
            }
        } else if (data instanceof GetMyShopinfo) {
            GetMyShopinfo goodSearch = (GetMyShopinfo) data;
            if (goodSearch.getCode() == 1) {
                if (offset == 1) {
                    image.setVisibility(View.GONE);
                    recycleStar.setVisibility(View.VISIBLE);
                    allSearch = goodSearch.getData();
                    shopAdapter = new ShopAdapter(this);
                    shopAdapter.setaddClick(new ShopAdapter.OnIntentClick() {
                        @Override
                        public void item(int posttion) {
                            Intent intent = new Intent(SearchActivity.this, CommodityDetailsActivity.class);
                            intent.putExtra("gid", allSearch.get(posttion).getGoods_id());
                            intent.putExtra("shop_id", allSearch.get(posttion).getShop_id());
                            startActivity(intent);
                        }
                    });
                    recycleStar.setAdapter(shopAdapter);
                } else {
                    allSearch.addAll(goodSearch.getData());
                }
                if (allSearch.size() > 0) {
                    recy_line.setVisibility(View.VISIBLE);
                    sou.setVisibility(View.GONE);
                }
                shopAdapter.setShopList(allSearch);
                offset++;
            } else {
                if (offset==1){
                    image.setVisibility(View.VISIBLE);
                    recycleStar.setVisibility(View.GONE);
                }else {
                    Toast.makeText(this, "暂无更多数据", Toast.LENGTH_SHORT).show();
                }
            }
            recycleStar.loadMoreComplete();
            recycleStar.refreshComplete();
        }
    }

    @Override
    public void fail(String error) {

    }

    @OnClick({R.id.shop_xiao, R.id.shop_lin_price, R.id.shop_renqi, R.id.lin_time,R.id.return_seach, R.id.searchclear, R.id.seach_sousuo, R.id.clear, R.id.laji, R.id.xiao, R.id.lin_price, R.id.renqi})
    public void onViewClicked(View view) {
        Map<String, String> map;
        switch (view.getId()) {
            case R.id.return_seach:
                finish();
                break;
            case R.id.searchclear:
                etSeach.setText("");
                break;
            case R.id.seach_sousuo:
                if (etSeach.getText().toString().equals("")) {
                    Toast.makeText(this, "请输入搜索内容", Toast.LENGTH_SHORT).show();
                    return;
                }
                offset=1;
                String s = etSeach.getText().toString();
//        1.店铺页面过来的 2.分类页面过来的   3.搜索按钮过来的
                if (type.equals("1")) {
                    map = new HashMap<>();
                    map.put("token", Constant.TOKEN);
                    map.put("shop_id", shop_id);
                    map.put("goodsName", s);
                    map.put("page",offset+"");
                    pressenter.sendMessage(this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);
                    recycleStar.setLoadingListener(new XRecyclerView.LoadingListener() {
                        @Override
                        public void onRefresh() {
                            offset = 1;
                            Map<String,String> map=new HashMap<>();
                            map.put("token", Constant.TOKEN);
                            map.put("shop_id", shop_id);
                            map.put("goodsName", s);
                            map.put("page",offset+"");
                            pressenter.sendMessage(SearchActivity.this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);
                        }
                        @Override
                        public void onLoadMore() {
                            Map<String,String> map=new HashMap<>();
                            map.put("token", Constant.TOKEN);
                            map.put("shop_id", shop_id);
                            map.put("goodsName", s);
                            map.put("page",offset+"");
                            pressenter.sendMessage(SearchActivity.this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);
                        }
                    });

                } else if (type.equals("2")) {

                    map=new HashMap<>();
                    map.put("token",Constant.TOKEN);
                    map.put("keyword",s);
                    map.put("page",offset+"");
                    pressenter.sendMessage(SearchActivity.this,Constant.CateSearch,map,GetMyShopinfo.class);

                    recycleStar.setLoadingListener(new XRecyclerView.LoadingListener() {
                        @Override
                        public void onRefresh() {
                            offset = 1;
                            Map<String,String> map=new HashMap<>();
                            map.put("token",Constant.TOKEN);
                            map.put("keyword",s);
                            map.put("page",offset+"");
                            pressenter.sendMessage(SearchActivity.this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);
                        }
                        @Override
                        public void onLoadMore() {
                            Map<String,String> map=new HashMap<>();
                            map.put("token",Constant.TOKEN);
                            map.put("keyword",s);
                            map.put("page",offset+"");
                            pressenter.sendMessage(SearchActivity.this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);
                        }
                    });
                } else {
                    search(s);
                }
                break;
            case R.id.clear:
                map = new HashMap<>();
                map.put("token", Constant.TOKEN);
                map.put("uid", uid);
                pressenter.sendMessage(SearchActivity.this, Constant.ClearMysearch, map, Bean.class);
                break;
            case R.id.laji:
                if (isshow.equals("1")) {
                    isshow = "0";
                    his_search.setVisibility(View.GONE);
                } else {
                    isshow = "1";
                    his_search.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.xiao:
                offset = 1;
                xiao.setTextColor(getResources().getColor(R.color.main));
                renqi.setTextColor(getResources().getColor(R.color.mainblack));
                price.setChecked(false);
                priceup.setImageResource(R.mipmap.priceupn);
                pricedown.setImageResource(R.mipmap.pricedownn);
                price.setTextColor(getResources().getColor(R.color.black));
                map = new HashMap<>();
                map.put("token", Constant.TOKEN);
                map.put("goods_name", value);
                map.put("page", offset + "");
                map.put("uid", uid);
                map.put("sale_num", "1");
                pressenter.sendMessage(SearchActivity.this, Constant.GoodSearch, map, GetMyShopinfo.class);
                break;
            case R.id.lin_price:
                offset = 1;
                price.setChecked(!price.isChecked());
                renqi.setTextColor(getResources().getColor(R.color.mainblack));
                xiao.setTextColor(getResources().getColor(R.color.mainblack));
                if (price.isChecked()) {
                    priceup.setImageResource(R.mipmap.priceups);
                    pricedown.setImageResource(R.mipmap.pricedownn);
                    map = new HashMap<>();
                    map.put("token", Constant.TOKEN);
                    map.put("goods_name", value);
                    map.put("page", offset + "");
                    map.put("uid", uid);
                    map.put("price", "1");
                    pressenter.sendMessage(SearchActivity.this, Constant.GoodSearch, map, GetMyShopinfo.class);
                } else {
                    priceup.setImageResource(R.mipmap.priceupn);
                    pricedown.setImageResource(R.mipmap.pricedowns);
                    map = new HashMap<>();
                    map.put("token", Constant.TOKEN);
                    map.put("goods_name", value);
                    map.put("page", offset + "");
                    map.put("uid", uid);
                    map.put("price", "2");
                    pressenter.sendMessage(SearchActivity.this, Constant.GoodSearch, map, GetMyShopinfo.class);
                }
                price.setTextColor(getResources().getColor(R.color.main));
                break;
            case R.id.renqi:
                offset = 1;
                xiao.setTextColor(getResources().getColor(R.color.mainblack));
                renqi.setTextColor(getResources().getColor(R.color.main));
                price.setChecked(false);
                priceup.setImageResource(R.mipmap.priceupn);
                pricedown.setImageResource(R.mipmap.pricedownn);
                price.setTextColor(getResources().getColor(R.color.black));
                map = new HashMap<>();
                map.put("token", Constant.TOKEN);
                map.put("goods_name", value);
                map.put("page", offset + "");
                map.put("uid", uid);
                map.put("renqi", "1");
                pressenter.sendMessage(SearchActivity.this, Constant.GoodSearch, map, GetMyShopinfo.class);
                break;
            case R.id.shop_xiao:
                offset = 1;

                shopXiao.setTextColor(getResources().getColor(R.color.main));
                shopRenqi.setTextColor(getResources().getColor(R.color.mainblack));
                shopPrice.setChecked(false);
                shopPriceup.setImageResource(R.mipmap.priceupn);
                shopPricedown.setImageResource(R.mipmap.pricedownn);
                shopPrice.setTextColor(getResources().getColor(R.color.black));
                time.setTextColor(getResources().getColor(R.color.mainblack));
                time.setChecked(false);
                timeup.setImageResource(R.mipmap.priceupn);
                timedown.setImageResource(R.mipmap.pricedownn);


                map = new HashMap<>();
                map.put("token", Constant.TOKEN);
                map.put("shop_id", shop_id);
                map.put("ct1", ct1);
                map.put("ct2", ct2);
                map.put("msort", "2");
                map.put("mdesc", "0");
                map.put("page",offset+"");
                pressenter.sendMessage(this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);

                recycleStar.setLoadingListener(new XRecyclerView.LoadingListener() {
                    @Override
                    public void onRefresh() {
                        offset = 1;
                        Map<String, String> map = new HashMap<>();
                        map.put("token", Constant.TOKEN);
                        map.put("shop_id", shop_id);
                        map.put("ct1", ct1);
                        map.put("ct2", ct2);
                        map.put("msort", "2");
                        map.put("page",offset+"");
                        pressenter.sendMessage(SearchActivity.this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);
                    }
                    @Override
                    public void onLoadMore() {
                        Map<String, String> map = new HashMap<>();
                        map.put("token", Constant.TOKEN);
                        map.put("shop_id", shop_id);
                        map.put("ct1", ct1);
                        map.put("ct2", ct2);
                        map.put("msort", "2");
                        map.put("page",offset+"");
                        pressenter.sendMessage(SearchActivity.this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);
                    }
                });


                break;
            case R.id.shop_lin_price:

                offset = 1;

                time.setTextColor(getResources().getColor(R.color.mainblack));
                time.setChecked(false);
                timeup.setImageResource(R.mipmap.priceupn);
                timedown.setImageResource(R.mipmap.pricedownn);
                shopPrice.setChecked(!shopPrice.isChecked());
                shopRenqi.setTextColor(getResources().getColor(R.color.mainblack));
                shopXiao.setTextColor(getResources().getColor(R.color.mainblack));
                if (shopPrice.isChecked()){
                    shopPriceup.setImageResource(R.mipmap.priceups);
                    shopPricedown.setImageResource(R.mipmap.pricedownn);
                    map = new HashMap<>();
                    map.put("token", Constant.TOKEN);
                    map.put("shop_id", shop_id);
                    map.put("ct1", ct1);
                    map.put("ct2", ct2);
                    map.put("msort", "3");
                    map.put("mdesc", "1");
                    map.put("page",offset+"");
                    pressenter.sendMessage(this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);
                    recycleStar.setLoadingListener(new XRecyclerView.LoadingListener() {
                        @Override
                        public void onRefresh() {
                            offset = 1;
                            Map<String, String> map = new HashMap<>();
                            map.put("token", Constant.TOKEN);
                            map.put("shop_id", shop_id);
                            map.put("ct1", ct1);
                            map.put("ct2", ct2);
                            map.put("msort", "3");
                            map.put("mdesc", "1");
                            pressenter.sendMessage(SearchActivity.this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);
                        }
                        @Override
                        public void onLoadMore() {
                            Map<String, String> map = new HashMap<>();
                            map.put("token", Constant.TOKEN);
                            map.put("shop_id", shop_id);
                            map.put("ct1", ct1);
                            map.put("ct2", ct2);
                            map.put("msort", "3");
                            map.put("mdesc", "1");
                            pressenter.sendMessage(SearchActivity.this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);
                        }
                    });

                }else {
                    shopPriceup.setImageResource(R.mipmap.priceupn);
                    shopPricedown.setImageResource(R.mipmap.pricedowns);
                    map = new HashMap<>();
                    map.put("token", Constant.TOKEN);
                    map.put("shop_id", shop_id);
                    map.put("ct1", ct1);
                    map.put("ct2", ct2);
                    map.put("msort", "3");
                    map.put("mdesc", "0");
                    map.put("page",offset+"");
                    pressenter.sendMessage(this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);
                    recycleStar.setLoadingListener(new XRecyclerView.LoadingListener() {
                        @Override
                        public void onRefresh() {
                            offset = 1;
                            Map<String, String> map = new HashMap<>();
                            map.put("token", Constant.TOKEN);
                            map.put("shop_id", shop_id);
                            map.put("ct1", ct1);
                            map.put("ct2", ct2);
                            map.put("msort", "3");
                            map.put("mdesc", "0");
                            map.put("page",offset+"");
                            pressenter.sendMessage(SearchActivity.this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);
                        }
                        @Override
                        public void onLoadMore() {
                            Map<String, String> map = new HashMap<>();
                            map.put("token", Constant.TOKEN);
                            map.put("shop_id", shop_id);
                            map.put("ct1", ct1);
                            map.put("ct2", ct2);
                            map.put("msort", "3");
                            map.put("mdesc", "0");
                            map.put("page",offset+"");
                            pressenter.sendMessage(SearchActivity.this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);
                        }
                    });

                }
                shopPrice.setTextColor(getResources().getColor(R.color.main));
                break;
            case R.id.shop_renqi:
                time.setTextColor(getResources().getColor(R.color.mainblack));
                time.setChecked(false);
                timeup.setImageResource(R.mipmap.priceupn);
                timedown.setImageResource(R.mipmap.pricedownn);
                shopXiao.setTextColor(getResources().getColor(R.color.mainblack));
                shopRenqi.setTextColor(getResources().getColor(R.color.main));
                shopPrice.setChecked(false);
                shopPrice.setTextColor(getResources().getColor(R.color.mainblack));
                shopPriceup.setImageResource(R.mipmap.priceupn);
                shopPricedown.setImageResource(R.mipmap.pricedownn);
                offset = 1;
                map = new HashMap<>();
                map.put("token", Constant.TOKEN);
                map.put("shop_id", shop_id);
                map.put("ct1", ct1);
                map.put("ct2", ct2);
                map.put("msort", "1");
                map.put("mdesc", "0");
                map.put("page",offset+"");
                pressenter.sendMessage(this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);

                recycleStar.setLoadingListener(new XRecyclerView.LoadingListener() {
                    @Override
                    public void onRefresh() {
                        offset = 1;
                        Map<String, String> map = new HashMap<>();
                        map.put("token", Constant.TOKEN);
                        map.put("shop_id", shop_id);
                        map.put("ct1", ct1);
                        map.put("ct2", ct2);
                        map.put("mdesc", "0");
                        map.put("msort", "1");
                        map.put("page",offset+"");
                        pressenter.sendMessage(SearchActivity.this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);
                    }
                    @Override
                    public void onLoadMore() {
                        Map<String, String> map = new HashMap<>();
                        map.put("token", Constant.TOKEN);
                        map.put("shop_id", shop_id);
                        map.put("ct1", ct1);
                        map.put("ct2", ct2);
                        map.put("msort", "1");
                        map.put("page",offset+"");
                        pressenter.sendMessage(SearchActivity.this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);
                    }
                });


                break;
            case R.id.lin_time:
//                上架时间
                offset = 1;
                shopRenqi.setTextColor(getResources().getColor(R.color.mainblack));
                shopXiao.setTextColor(getResources().getColor(R.color.mainblack));
                shopPrice.setTextColor(getResources().getColor(R.color.mainblack));
                time.setTextColor(getResources().getColor(R.color.main));
                shopPrice.setChecked(false);
                shopPriceup.setImageResource(R.mipmap.priceupn);
                shopPricedown.setImageResource(R.mipmap.pricedownn);
                priceup.setBackgroundResource(R.mipmap.priceupn);
                pricedown.setBackgroundResource(R.mipmap.pricedownn);
                time.setChecked(!time.isChecked());
                if (time.isChecked()){
                    timeup.setImageResource(R.mipmap.priceups);
                    timedown.setImageResource(R.mipmap.pricedownn);
                    map = new HashMap<>();
                    map.put("token", Constant.TOKEN);
                    map.put("shop_id", shop_id);
                    map.put("ct1", ct1);
                    map.put("ct2", ct2);
                    map.put("msort", "6");
                    map.put("mdesc", "1");
                    map.put("page",offset+"");
                    pressenter.sendMessage(this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);
                    recycleStar.setLoadingListener(new XRecyclerView.LoadingListener() {
                        @Override
                        public void onRefresh() {
                            offset = 1;
                            Map<String, String> map = new HashMap<>();
                            map.put("token", Constant.TOKEN);
                            map.put("shop_id", shop_id);
                            map.put("ct1", ct1);
                            map.put("ct2", ct2);
                            map.put("msort", "6");
                            map.put("mdesc", "1");
                            map.put("page",offset+"");
                            pressenter.sendMessage(SearchActivity.this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);
                        }
                        @Override
                        public void onLoadMore() {
                            Map<String, String> map = new HashMap<>();
                            map.put("token", Constant.TOKEN);
                            map.put("shop_id", shop_id);
                            map.put("ct1", ct1);
                            map.put("ct2", ct2);
                            map.put("msort", "6");
                            map.put("mdesc", "1");
                            map.put("page",offset+"");
                            pressenter.sendMessage(SearchActivity.this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);
                        }
                    });
                }else {
                    timeup.setImageResource(R.mipmap.priceupn);
                    timedown.setImageResource(R.mipmap.pricedowns);
                    map = new HashMap<>();
                    map.put("token", Constant.TOKEN);
                    map.put("shop_id", shop_id);
                    map.put("ct1", ct1);
                    map.put("ct2", ct2);
                    map.put("msort", "6");
                    map.put("mdesc", "0");
                    map.put("page",offset+"");
                    pressenter.sendMessage(this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);

                    recycleStar.setLoadingListener(new XRecyclerView.LoadingListener() {
                        @Override
                        public void onRefresh() {
                            offset = 1;
                            Map<String, String> map = new HashMap<>();
                            map.put("token", Constant.TOKEN);
                            map.put("shop_id", shop_id);
                            map.put("ct1", ct1);
                            map.put("ct2", ct2);
                            map.put("msort", "6");
                            map.put("mdesc", "0");
                            map.put("page",offset+"");
                            pressenter.sendMessage(SearchActivity.this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);
                        }
                        @Override
                        public void onLoadMore() {
                            Map<String, String> map = new HashMap<>();
                            map.put("token", Constant.TOKEN);
                            map.put("shop_id", shop_id);
                            map.put("ct1", ct1);
                            map.put("ct2", ct2);
                            map.put("msort", "6");
                            map.put("mdesc", "0");
                            map.put("page",offset+"");
                            pressenter.sendMessage(SearchActivity.this, Constant.GetShopGoodsList, map, GetMyShopinfo.class);
                        }
                    });

                }
                break;
            default:
        }
    }

}
